﻿/*!
 * 树列表集对象.
 * ecp.qzz.treedataset.js
 * 创建：QZZ
 * 日期：2014-03-01
 */
define(["qzz.treelist","qzz.expression","qzz.date"], function() {
	
	var qzz = window.qzz;
	/**
	 * @class 树列表集对象.
	 */
	qzz.treedataset = qzz.Class(qzz.treelist, {
		/**
		 * 创建函数.
		 */
		_create:function() {
		    this.base();
		    this.className = "TreeDataSet";
		    this.logInfo("TreeDataSet.create");    
		    this.option.colModels = [];
		    this.option.viewColModels = [];
		    //扩展状态
		    this.storeData = true;
		    //字段属性对象
		    this.fieldOption = {};
		    //名称ID转换对象
		    this.transIDName = {};
		    //过滤条件的顶点.
		    this.topFilterItem = null;
		    //过滤筛选
		    this.filterList = {};
		    //选择的过滤条件
		    this.selectFilterList = {};
		    //索引字段.
		    this.PKeyName = [];
		    //索引
		    this.keyNodeJson = {};
		    //字段分隔符.
			this.fieldSplit = "$";
			this.valueSplit = "_";
			this.keySplit = "^";
			this.nodeBegin = "#{";
			this.nodeEnd = "}";
			this.pathSplit = ".";
			//表达式列表.
			this.expList = [];
			//GJ表达式列表.
			this.expGJList = [];
			//列GJ表达式列表
			this.expColGJList = [];
			//顶层合计列.
			this.sumList = {};
			//名称转换状态
			this.transState = {};
			//排序缓存
			this.sortCach = {};
			//转换序号.
			this.transIndex = 0;
			//反向勾稽
			this.reverGJ = false;
		    /*
		     * 数据元单位.
		     * 千分号、百分号、1、10、到1000000为单位
		     */
		    this.numUnit = {
		    	 perthousand:0.001,
		         percent:0.01,
		         one:1,
		         ten:10,
		         hundred:100,
		         thousand:1000,
		         tenThousand:10000,
		         hundredThousand:100000,
		         million:1000000
		    }
		    this.sortFieldName = null;
		    //过滤状态.
		    this.filtered = false;
		    //日期对象
		    this.dateObject = new qzz.date();
	    },
	    /**
	     * 获取转换model
	     * @return 返回名称转换model
	     */
	    getDisplayModel:function() {
	    	if(this.displayModel == null) {
	    		this.displayModel = this.getDataSource().getDisplayModel();
	    	}
	    	return this.displayModel;
	    },
	    /**
	     * 异步获取格式化后的数据.
	     */
	    _asynGetDisplayData:function(reAry, fieldNames, node, cNode, limitCount, type, callBack) {
	    	this.logInfo("_asynGetDisplayData");
	    	if(this.getAllCount() > 0) {
		    	if(node == null) {
		    		node = this.rootNode;
		    	}
		    	if(cNode == null) {
		    		cNode = this.getChildNode(0, node);//node.cNode[0];
		    	}
		    	var ui = this.beginUpdate(true);
		    	var tmpNode = this.getCurNode();
		    	this.select(cNode);
		    	this.logInfo("_asynGetDisplayData:" + cNode.scrIndex);
		    	var i = 0;
		    	var len = fieldNames.length;
		    	var levelSpace = {};
		    	//循环处理排序
		    	while(!this.isEof() && this.getLevel() > node.level && i < limitCount) {
		    		var cNode = this.getCurNode();
		    		var fnAry = null;
		    		if(type === "json") {
		    			fnAry = {};
		    			for(var j = 0; j < len; j++) {
		    				var fn = fieldNames[j];
			    			val = this.getDisplay(fn);
			    			if(j == 0 && this.isTree && cNode.level > 0) {
			    				var sj = levelSpace[cNode.level];
			    				if(sj == null) {
			    					sj = "";
				    				for(var k = 0; k < cNode.level; k++) {
				    					sj += "  ";
				    				}
				    				levelSpace[cNode.level] = sj;
			    				}
			    				val = sj + val;
			    			}
			    			fnAry[fn] = val;
			    		}
		    		} else {
			    		fnAry = [];
			    		for(var j = 0; j < len; j++) {
			    			var fn = fieldNames[j];
			    			val = this.getDisplay(fn);
			    			if(j == 0 && this.isTree && cNode.level > 0) {
			    				var sj = levelSpace[cNode.level];
			    				if(sj == null) {
			    					sj = "";
				    				for(var k = 0; k < cNode.level; k++) {
				    					sj += "  ";
				    				}
				    				levelSpace[cNode.level] = sj;
			    				}
			    				val = sj + val;
			    			}
			    			fnAry.push(val);
			    		}
		    		}
		    		reAry.push(fnAry);
		    		this.next(true);
		    		i++;
		    	}
		    	levelSpace = null;
		    	if(!this.isEof() && this.getLevel() > node.level) {
		    		//如果没有处理完，则异步再调用
		    		var _this = this;
		    		cNode = this.getCurNode();
		    		setTimeout(function(){_this._asynGetDisplayData(reAry, fieldNames, node, cNode, limitCount, type, callBack); _this = null}, 10);
		    	} else {		    	    
		    		//回调函数
		    		if(typeof callBack == "function") {
		    		    callBack(reAry);
		    		}
		    	}
		    	this.select(tmpNode);
		    	this.endUpdate(false, ui);
		    	tmpNode = null;
	    	} else {
	    		if(typeof callBack === "function") {
	    			callBack(reAry);
	    		}
	    	}
	    },
	    /**
	     * 获取格式化后的数据.
	     * @getDisplayData
	     * @return {Array} 数据列表.
	     */
	    getDisplayData:function(fieldNames, type, callBack) {
	    	if(typeof type === "function") {
	    		callBack = type;
	    		type = "array";
	    	}
	    	var reAry = [];
	    	this._asynGetDisplayData(reAry, fieldNames, undefined, undefined, 500, type, callBack);
	    },
	    /**
	     * 打开.
	     */
	    open:function() {
	    	
	    },
	    /**
	     * 关闭.
	     */
	    close:function() {
	    	
	    },
	    /**
	     * 数据集的配置.
	     */
	    setColModels : function(colModels) {
	    	this.option.colModels = colModels;
	    	if(this.option.colModels == null) {
	    		this.option.colModels = [];
	    	}
	    	this.fieldOption = {};
	    },
	    /**
	     * 视图的配置.
	     */
	    setViewColModels:function(vColModels) {
	    	this.option.viewColModels = vColModels;
	    	if(this.option.viewColModels == null) {
	    		this.option.viewColModels = [];
	    	}
	    	this.fieldOption = {};
	    },
	    /**
	     * 获取字段属性.
	     * @param fieldName 字段名称
	     * @return 返回属性对象
	     */
	    getColModel:function(fieldName) {
	    	var re = this.fieldOption[fieldName];
	    	if(re == null) {
	    		for(var i = 0, len = this.option.colModels.length; i < len; i++) {
	    			var field = this.option.colModels[i];
	    			if(field.name === fieldName) {
	    				re = field;
	    			}
	    			field = null;
	    		}
	    		var cre;
	    		for(var i = 0, len = this.option.viewColModels.length; i < len; i++) {
	    			var cm = this.option.viewColModels[i];
	    			if(cm.name === fieldName) {
	    				cre = cm;
	    			}
	    		}
	    		if(re != null) {
	    			re = this.extend({},re);
	    		} else {
	    			re = {};
	    		}
	    		if(cre != null) {
	    			re = this.extend(re, cre);
	    		}
	    		this.fieldOption[fieldName] = re;
	    	}
	    	return re;
	    },
	    /**
	     * 获取字段属性.
	     * @param fieldName 字段名称
	     * @return 返回属性对象
	     */
	    getFieldOption:function(fieldName) {
	    	return this.getColModel(fieldName);
	    },
	    /**
	     * 获取字段数据类型.
	     * @param fieldName 字段名称
	     * @return 返回
	     */
	    getDataType:function(fieldName) {
	    	var dt = this.getColModel(fieldName).dataType;
	    	if(this.isEmpty(dt)) {
	    		dt = "String";
	    	}
	    	return dt.toLowerCase();
	    },
	    /**
	     * 获取字段数据值.
	     * @param fieldName 字段名称
	     * @param node 节点
	     * @return 返回值
	     */
	    getValue:function(fieldName, node) {
	    	var node = node || this.curNode;
	    	if(fieldName == null) {
	    		return "";
	    	}
	    	var re;
	    	var cm = this.getColModel(fieldName);	    		    	
	    	if(fieldName.indexOf(".") >= 0) {
	    		//处理子节点情况
		    	var fnAry = fieldName.split(".");
		    	var re = node.data[fnAry[0]];
		    	if(re == null) {
		    		return re;
		    	}
		    	for(var i = 1, len = fnAry.length; i < len; i++) {
		    		re = re[fnAry[i]];
		    	}
	    	} else {
	    		if(node.data != null) {
	    		    re = node.data[fieldName];
	    		}	    		
	    		if(re!=null){
	    			if( typeof re == "string" && re.indexOf("</a>")>-1 ){ re = $(re).text();}
				}
	    	}	    	
	    	if(typeof cm.onGetValue == "function" && node != null) {
	    		try {
	    		    re = cm.onGetValue(this, re, node, fieldName);
	    		} catch(e) {
	    			this.logInfo("col " + fieldName + " getDisplay Error:" + e.message);
	    		}
	    	}
	    	cm = null;
	    	node = null;
	    	//处理转义
	    	if(typeof re == "string") {
	    		re = this._tagToText(re);
    	    }
	    	return re == null ? "" : re;
	    },
	    /**
	     * 获取合计值.
	     * @param fieldName 字段名称
	     * @return 返回值
	     */
	    getSummary:function(fieldName) {
	    	return this.getTotalValue(fieldName);
	    },
	    /**
	     * 获取合计值.
	     * @param fieldName 字段名称
	     * @param value 值
	     * @return 返回值
	     */
	    setSummary:function(fieldName, value) {
	    	this.setTotalValue(fieldName, value);
	    },
	    /**
	     * 获取合计值.
	     * @param fieldName 字段名称
	     * @return 返回值
	     */
	    getTotalValue:function(fieldName) {
	    	if(this.rootNode.data == null) {
	    		this.rootNode.data = {};
	    	}
	    	return this.getValue(fieldName, this.rootNode);
	    },
	    /**
	     * 获取合计值.
	     * @param fieldName 字段名称
	     * @param value 值
	     * @return 返回值
	     */
	    setTotalValue:function(fieldName, value) {
	    	if(this.rootNode.data == null) {
	    		this.rootNode.data = {};
	    	}
	    	this.setValue(fieldName, value, this.rootNode);
	    },
	    /**
	     * 小计值.
	     * @param fieldName 列字段
	     */
	    getSubtotalValue:function(fieldName) {
	    	if(this.subNode.data == null) {
	    		this.subNode.data = {};
	    	}
	    	return this.getValue(fieldName, this.subNode);
	    },
	    /**
	     * 设置小计值
	     * @param fieldName 字段
	     * @param value 值
	     */
	    setSubtotalValue:function(fieldName, value) {
	    	if(this.subNode.data == null) {
	    		this.subNode.data = {};
	    	}
	    	this.setValue(fieldName, value, this.subNode);
	    },
	    /**
	     * 获取单元格属性.
	     */
	    getOption:function(fieldName, node) {
	    	if(fieldName == null && node == null) {
	    		return this.base();
	    	} else {
	    		return this.getCellOption(fieldName, node);
	    	}
	    },
	    /**
	     * 获取当前单元格属性.
	     * @param fieldName 字段名称。
	     */
	    getCellOption:function(fieldName, node) {
	    	if(node == null) {
	    	    node = this.curNode;
	    	}
	    	if(node.option == null) {
	    		node.option = {};
	    	}	    	
	    	if(node.option[fieldName] == null) {
	    		node.option[fieldName] = {};
	    	}
	    	return node.option[fieldName];
	    },
	    getRefTypeValues:function(cm) {
	    	return $.ecp.utils.getRefTypeValues(cm)
	    },
	    /**
	     * 设置text值到模型中.
	     * @param fieldName 字段名称
	     * @param text 字符串
	     */
	    setDisplay:function(fieldName, text, node) {
	    	var dataType = this.getDataType(fieldName);
	    	var metaItem = this.getColModel(fieldName);
	    	var value = ""; 
	    	var canUpdate = true;
	    	if(dataType == "date") {
	    		//日期格式转换
	    		var cv = this.getValue(fieldName);
	    		if(isNaN(cv) || typeof cv === "string") {
	    		    value = this.dateObject.parseEcpDate(text);
	    		} else {
	    			this.dateObject.setShowTime(false);
	    			text = this.dateObject.checkDate(text);
	    			value = Date.parse(text.replace(/-/g,'/'));
	    		}
	    	} else if(dataType == "gldx" || dataType == "dxfl" 
	    		|| dataType == "unitcode" || dataType == "ecp.tableentity"
	    		    || dataType == "enum" || dataType === "sysenum") {
	    		//管理对象，对象分类，单位转换处理
	    		var hasData = false;
	    		canUpdate = false;
	    		var txtAry = text.split(","), vals = [];
	    		var tlen = txtAry.length;
	    		//先从模型中获取idname列表	    		
	    		if(this.isNotEmpty(this.transIDName) && this.isNotEmpty(this.transIDName[fieldName])) {
	    			var idns = this.transIDName[fieldName];
	    			for(var key in idns) {
	    				for(var i = 0; i < tlen; i++) {
		    				if(idns[key] === txtAry[i]) {
		    					vals.push(key);
		    					canUpdate = true;
		    				}
	    				}
	    				hasData = true;
	    			}
	    			value = vals.join(",");
	    		}
	    	} else if(dataType == "number" || dataType == "money") {
	    		//数值型处理
	    		if(this.isNotEmpty(text)) {
	    			//去掉百分号、千分号、千分符等
	    			canUpdate = false;
	    			value = text.replace(/[,%‰]/g,"");
	    			if(!isNaN(value) && this.isNotEmpty(value)) {
	    			    value = parseFloat(value, 10);
			    	    if(this.isNotEmpty(metaItem.numUnit)) {
			    	    	value = value * parseFloat(metaItem.numUnit, 10);
			    	    }
		    	        var ds = metaItem.precision || metaItem.dataScale || metaItem.scale || 0;
		    	        if(ds < 0) {
		    	        	ds = 0;
		    	        }
		    	        //处理精度
		    	        var fv = new Number(value);
		    	        value = parseFloat(fv.toFixed(ds), 10);
		    	        canUpdate = true;
	    			}
	    	    }
	    	} else {
	    		value = text;
	    	}
	    	if(canUpdate) {
	    		if(typeof metaItem.onSetDisplay == "function") {
		    		try {
		    		    value = metaItem.onSetDisplay(this, text, node);
		    		} catch(e) {
		    			this.logInfo("col " + fieldName + " setDisplay Error:" + e.message);
		    		}
		    	}
	    		//格式化数据
		    	if(this.hasbind("onSetText_" + fieldName)) {
					try {
				        value = this.trigger("onSetText_" + fieldName, [this, text, node]);
					} catch(e) {
						this.logInfo("col " + fieldName + " SetText Error:" + e.message);
					}
				}
	    		metaItem = null;
	    	    this.setValue(fieldName, value);
	    	}
	    },
	    /**
	     * 获取displayModel中的id名称转换列表.
	     * @param {string} fieldName 字段
	     * @return {JSON} 返回json对象
	     */
	    _getDisplayTextAsJson:function(fieldName) {
	    	var metaItem = this.getColModel(fieldName);    	
	    	var dataType = this.getDataType(fieldName);
	    	var rtv = this.getRefTypeValues(metaItem);
    		var dpm = this.getDisplayModel();
    		var inJson = null;
    		if(dataType == "enum" || dataType === "sysenum") {
	    		if(dpm != null) {
		    		//获取名称转换列表
	    			inJson = dpm.displayModel[rtv[0].classId.toUpperCase()];
	    			if(this.isEmpty(inJson) || this.isEmpty(inJson[rtv[0].typeId])) {
	    				dpm.getMc({refTypeValues : rtv, id: "1"});
	    			    inJson = dpm.displayModel[rtv[0].classId.toUpperCase()];
	    			}
	    			dpm = null;
	    		}
    		} else {
    			//调用通用名称转换函数	    			
    			window.dataType = "STRING";
    			var dpm = $.ecp.getDisplayModel({ 
    					"metaItems":this.getDataSource().getMetaDataModel().get(this.getName()).value(),
    					"transData":this._tmpData || this.getDataSource().getDataModel().get(this.getName()).value(),
    					"dataModel":this.getDataSource().getDataModel()
    			});		 
    			this.getDisplayModel().displayModel = 
    					this.extend(this.getDisplayModel().displayModel, dpm.displayModel);
    			inJson = this.getDisplayModel().displayModel[rtv[0].classId.toUpperCase()];   			
    		}
    		//如果是枚举的时候，还要进入一层
			if(this.isNotEmpty(inJson) && this.isNotEmpty(inJson[rtv[0].typeId])) {
		        inJson = inJson[rtv[0].typeId];
			}
			var datas = {};
			if(this.isNotEmpty(inJson)) {
				var i = 0;				
			    for(var key in inJson) {
			    	var textStr = inJson[key];
			    	if(typeof textStr == "object") {
			    		textStr = textStr.name;
			    	}
			    	if(this.isNotEmpty(key)) {
    			    	datas[key] = textStr;
			    	}
			    }
			}
			inJson = null;
			rtv = null;	
			return datas;
	    },
	    /**
	     * 获取显示用的值. 
	     * @param fieldName 字段名
	     * @param value 值 
	     * @param node 节点
	     * @return 返回显示值
	     */
	    getDisplay:function(fieldName, value, node, nodeCach) {
	    	var isOld = false;
	    	if(node == null) {
	    		node = this.curNode;
	    	}
	    	if(value == null) {
	    	    value = this.getValue(fieldName, node);
	    	    isOld = true;
	    	}
	    	var option = this.getCellOption(fieldName, node);
	    	if(nodeCach == true) {
	    		option.displayText = null;
	    	}
	    	var metaItem = this.getColModel(fieldName);    	
	    	var dataType = this.getDataType(fieldName);
	    	if(this.transState[fieldName] == null) {
	    		this.transState[fieldName] = {};
	    	}
	    	var isMulti = false;
	    	if(metaItem.option != null) {
	    		isMulti = metaItem.option.multiselect == true || metaItem.isSingle == false 
	    		    || metaItem.option.isMulti == true || metaItem.option.isMutil == true
	    		    || metaItem.option.isMulti == "true" || metaItem.option.isMutil == "true";
	    	}
	    	isMulti = isMulti || metaItem.multiSelect === true
	    	var oldValue = value;
	    	if(dataType == "date") {
	    		//判断是否有缓存
	    		if(value !== "" && value != null) {
		    		//option = this.getCellOption(fieldName);
		    		if(isOld && this.isNotEmpty(option.displayText) && this.transIndex === option.transIndex) {
		    			value = option.displayText;
		    		} else if(value !== null 
		    			    && value !== "" && value != "NaN") {
		    		    //日期转换处理
		    			var showTime = false
		    			var showType = "day";
		    			showTime = this.getBooleanValue(metaItem.showTime, false);	
		    			showType = metaItem.cyctype || showType;
		    			if(metaItem.showType === "M") {
		    				showType = "month";
		    			}
		    			showTime = showTime || showType === "hour" || showType === "minute" || showType === "second";
		    			//调用转换函数
		    			if(typeof value == "string" && value.indexOf("Date") >= 0) {
		    				value = this.dateObject.strToDate(value, showTime, undefined, true);
		    			}
		    			//处理显示时间，及日期周期
		    			this.dateObject.setShowTime(showTime);	    				
		    			this.dateObject.cyctype = showType;
		    			value = this.dateObject.toDate(value);
		    			if(showType == this.dateObject.cyctypes.season) {
		    				value = this.dateObject.getFormatDate(value);
		    			}
		    			if(isOld) {
			    			option.displayText = value;
			    			option.transIndex = this.transIndex;
		    			}
		    		}	    	
	    		}
	    	} else if(dataType == "number" || dataType == "integer"	    		
	    		|| dataType == "int" || dataType == "float") {
	    		if(value !== "" && value != null) {
		    	    //判断是否存在缓存.
		    		//option = this.getCellOption(fieldName);
		    		if(isOld &&  this.isNotEmpty(option.displayText) 
		    				&& this.transIndex === option.transIndex
		    				    && option._oldValue === value) {
		    			value = option.displayText;
		    		} else {
		    			option._oldValue = value;
		    			if(this.isNotEmpty(value) && !isNaN(value)) {
		    				if(this.transIDName != null 
		    						&& this.transIDName[fieldName] != null 
		    						    && this.transIDName[fieldName][value]) {
		    		    		value = this.transIDName[fieldName][value];
			    			} else {
					    	    //处理元单位
					    	    if(this.isNotEmpty(metaItem.numUnit)) {
					    	    	value = value/parseFloat(metaItem.numUnit, 10);
					    	    }
				    	        var ds = metaItem.precision || metaItem.dataScale|| metaItem.scale || 0;
				    	        if(ds < 0) {
				    	        	ds = 0;
				    	        }
				    	        //处理精度
				    	        var fv = new Number(value);
				    	        if(metaItem.hideZero && fv == 0) {
				    	        	value = "";
				    	        } else {
				                    value = fv.toFixed(ds);
				                    if(ds < 7 && (value + "").indexOf("e") > 0) {
				                    	value = 0;
				                    }
				                    if(metaItem.noFormat !== true) {
				                        value = this.numberFormat(value);
				                    }
				                    if(metaItem.numUnit == this.numUnit.perthousand) {
				                    	value += "‰";
				                    } else if(metaItem.numUnit == this.numUnit.percent) {
				                    	value += "%";
				                    }
				    	        }
			    			}
			    	    }
		    			if(isOld) {
				    	    option.displayText = value;
				    	    option.transIndex = this.transIndex;
		    			}
		    		}
		    	}
	    	} else {
	    		if(value !== "" && value != null) {
	    			if(isOld &&  this.isNotEmpty(option.displayText) 
	    					&& this.transIndex === option.transIndex) {
		    			value = option.displayText;
		    		} else {
		    			var tnames = {};
		    			if(this.transIDName != null 
	    						&& this.transIDName[fieldName] != null) {
		    				tnames = this.transIDName[fieldName];	    		    		
		    			}
		    			if(isMulti) {
		    				if(typeof value == "string") {
		    					var vaAry = value.split(/[,，]/g);
		    					var naAry = [];
		    					for(var i = 0, len = vaAry.length; i < len; i++) {
		    						var cns = tnames[vaAry[i]];
		    						if(cns != null) {
		    							naAry[i] = cns;
		    						} else {
		    							naAry[i] = vaAry[i];
		    						}
		    					}
		    					value = naAry.join(",");
		    				} else if(tnames[value] != null){
		    					value = tnames[value];
		    				}
		    			} else if(tnames[value] != null){
		    			    value = tnames[value];
		    			}
		    			tnames = null;
		    			if(isOld) {
				    	    option.displayText = value;
				    	    option.transIndex = this.transIndex;
		    			}
		    		}
	    		}
	    	}
	    	
	    	//原来是空的情况下，如果有效验
	    	if(this.isNotEmpty(metaItem.validate) && (value === "" || value == null) 
	    			&& option.displayText !== "" && option.displayText != null) {
	    		value = option.displayText;
	    	}
	    	//自动做转换处理.
	    	if(metaItem.textField != null && metaItem.textField !== "") {
	    		value = this.getValue(metaItem.textField);
	    	}
	    	//转换字段
	    	if(metaItem.transKey != null && metaItem.transKey !== "") {
	    		value = this.getValue(metaItem.transKey);
	    	}
	    	//格式化事件
	    	if(this.hasbind("onBeforeFormat_" + fieldName)) {
	    		//oldValue -> value   
	    		//value -> text
	    		var value = this.trigger("onBeforeFormat_" + fieldName, [node, fieldName, oldValue, value, metaItem]);
	    	}
	    	//格式化数据
	    	if(this.hasbind("onFormat_" + fieldName)) {
				try {
			        value = this.trigger("onFormat_" + fieldName, [node, fieldName, dataType, value, metaItem]);
				} catch(e) {
					this.logInfo("col " + fieldName + " format Error:" + e.message);
				}
			}
	    	metaItem = null;
	    	return value == null ? "" : value;
	    },
	    /**
	     * 设置值.
	     * @param fieldName 字段
	     * @param value 值
	     * @param node 节点
	     */
	    setValue:function(fieldName, value, node, notCac) {
	    	if(fieldName == null) return false;
	    	var node = node || this.curNode;
	    	var dataType = this.getDataType(fieldName); 
	    	var isNull = this.isEmpty(value);
	    	var mdm = this.getColModel(fieldName);
	    	if(dataType == "date") {
	    		//日期转换处理
	    		if(!isNull) {
	    			if(value.value != null) {
	    				value = value.value;
	    			}
	    			//调用转换函数
	    			if(this.isNotEmpty(value) && typeof value == "string" && value.indexOf("Date(") < 0) {
	    				var cv = this.getValue(fieldName, node);
	    				if(isNaN(cv) || typeof cv === "string") {
	    			        value = this.dateObject.parseEcpDate(value);
	    				} else {
	    	    			value = Date.parse(value.replace(/-/g,'/'));
	    				}
	    			}
	    		}
	    		if(value === "") {
	    			value = null;
	    		}
	    	} else if(dataType == "gldx" || dataType == "dxfl" || dataType == "unitcode" 
	    		    || dataType == "enum" || dataType === "sysenum") {
	    		//管理对象，对象分类，单位转换处理
	    		if(!isNull && typeof value == "object") {
	    			if(this.isArray(value)) {
	    				value = value.join(",");
	    			} else {
	    		        value = value.value;
	    			}
	    		}
	    	} else if(dataType == "number" || dataType == "money") {
	    		//数值型
	    		if(this.transIDName != null 
						&& this.transIDName[fieldName] != null ) {
	    			var idns = this.transIDName[fieldName];
	    			for(var idnKey in idns) {
	    				if(idns[idnKey] == value) {
	    					value = idnKey;
	    					break;
	    				}
	    			}
    			}
	    		var ds = mdm.precision || mdm.dataScale|| mdm.scale || 0;
	    		if(mdm.numUnit != null && mdm.numUnit !== "") {
	    			var nu = mdm.numUnit +"";
	    			var nuinx = nu.indexOf(".");
	    			if(nuinx != -1) {
	    				ds = ds + nu.length - nuinx - 1;
	    			}
	    		}
	    		value = this.round(value,ds);	    		
				if(mdm.minValue != null && value < mdm.minValue || mdm.maxValue != null && value > mdm.maxValue) {
					return false;
				}
	    		//超大数值时
	    		if((value + "").replace(/[.\-,%‰]/gi,"").length > 17) {
	    			var pindex = (value + "").indexOf(".");
	    	        if(ds < 0) {
	    	        	ds = 0;
	    	        }
	    			if(pindex == -1 || pindex + ds > 17) {
		    			this.logError("数值 " + value + " 太大，无法提交。"); 
		    			return false;
	    			}
	    		}
	    	} else if(dataType === "string") {
				if(this.isArray(value)) {
	    		    value = value.join(",");
				}
				if(mdm.length != null && mdm.length > 0 && !isNull && this.strLen(value) > mdm.length) {
					//数据库中，一个汉字占两个长度
					value = this.subStr(value, mdm.length);
				}
				
	    	}
	    	var ov = this.getValue(fieldName, node);
	    	//合计行设置.
	    	if(node.level < 0) {
	    		if(node.data == null) {
	    			node.data = {};
	    		}
	    		if(fieldName.indexOf(".") >= 0) {
		    		//处理子节点情况
			    	var fnAry = fieldName.split(".");
			    	var i = 1;
			    	while(i < len) {
			    		if(node.data[fnAry[i]] == null) {
			    			node.data[fnAry[i]] = {};
			    		}
			    		i++;
			    	}
			    	node.data[fnAry[i - 1]] = value;
		    	} else {
		    		node.data[fieldName] = value;
		    	}
	    		//编辑后事件
	    		if(this._update && this.hasbind("onTotalChanged") === true) {
	    		    this.trigger("onTotalChanged",[fieldName, ov, value, node]);
	    		}
		    	node = null;
	    	} else if(isNull || !this.isEmpty(value) && (""+value) != "NaN") {
	    		//如果发生变量，把缓存的text清空
	    		var cellOption = this.getCellOption(fieldName, node);
	    		cellOption.displayText = "";
	    		//较验，且没有通过不允许提交
	    		if(this.isNotEmpty(mdm.validate)) {
	    			var valiShow = this.validateValue(mdm.validate, node, fieldName, value);
	    			if(!valiShow.state) {
	    				cellOption.displayText = value;
	    				cellOption.validateMessage = valiShow.message;
	    				if(mdm.validateSumit !== true) {
	    					return false;
	    				}
	    			} else {
	    				cellOption.validateMessage = null;
	    			}
	    			cellOption.hasValidate = true;
	    		}
	    		//把数据设置到模型中
	    		if(isNull && this.isEmpty(ov) || !isNull && ov !== 0 && ov !== "" && ov == value) return false;	    		
	    		//更新数据到节点上.
		    	if(fieldName.indexOf(".") >= 0) {
		    		//处理子节点情况
			    	var fnAry = fieldName.split(".");
			    	var re = node.data[fnAry[0]];
			    	if(re != null) {
			    		var i = 1;
				    	for(var len = fnAry.length; i < len - 1; i++) {
				    		re = re[fnAry[i]];
				    	}
				    	re[fnAry[i]] = value;
				    	if(cellOption.changed == null) {
			    			if(re._oldValue == null) {
			    				re._oldValue = {};
			    			}
			    			re._oldValue[fieldName] = ov;
			    		}
			    	}
		    	} else {
		    		node.data[fieldName] = value;
		    		if(cellOption.changed == null) {
		    			if(node.data._oldValue == null) {
		    				node.data._oldValue = {};
		    			}
		    			node.data._oldValue[fieldName] = ov;
		    		}
		    	}
	    		cellOption._pValue = ov;
	    		cellOption.changed = true;
	    		cellOption.displayText = "";
	    		if(node.data.modelState != 4) {
	    		    node.data.modelState = node.data.modelState | this.modelState.MODIFY;
	    		}
	    		if(this._changeSet.modify[node.recNo] == null) {
	    			this._changeSet.modify[node.recNo] = node;
	    		}
	    		//管理对象，设置新值上来的时候，id名称转换需要重新获取
	    		if(this.transState != null && this.transState[key] != null 
	    				&& this.transState[key].transed	&& this.transIDName != null) {
	    			var idn = this.transIDName[fieldName];
	    			if(idn != null && idn[value] == null) {
	    				this.transState[key].transed = false;
	    			}
	    		}
	    		//清空排序,与过滤列表,最大text记录
	    		node.pNode.sortChanged[fieldName] = true;
	    		//this.filterList[fieldName] = {};
	    		this._setFilterChangedState(fieldName, ov, value);
	    		if(this.maxText != null) {
	    		    this.maxText[fieldName] = null;
	    		    this.maxTextLen[fieldName] = 0;
	    		    this.maxCapWidth[fieldName] = 0;
	    		}
	    		//编辑后事件
	    		if(this._update && this.hasbind("onEdited") === true) {
	    		    this.trigger("onEdited",["modify", fieldName, ov, value, node]);
	    		}
	    		//运算状态标志
	    		if(cellOption.cacPCells != null) {
	    			for(var key in cellOption.cacPCells) {
	    				var nodeObj = cellOption.cacPCells[key];
	    				if(nodeObj.node == null) {
	    					nodeObj.node = this.getKeyNode(nodeObj.keyFieldName, nodeObj.keyValue);
	    				}
	    				if(nodeObj.node != null) {
	    				    this.getCellOption(nodeObj.fieldName, nodeObj.node).cacState = 1;
	    				}
	    			}
	    			if(notCac !== true) {
	    				this.caculate();
	    			}
	    		}
	    		if(notCac !== true && this.sumList[fieldName] != null) {
	    		    this.sumList[fieldName] = 1;
	    		    if(ov == null || ov === "") {
	    		    	ov = 0;
	    		    }
	    			this.caculateSum(false, fieldName, ov, value, node);
	    		}
	    	}
	    	node = null;
	    	mdm = null;
	    	return true;
	    },
        mergeChangeLog:function(ids) {
        	this._changeSet.deleteList = [];
        	if(ids != null && ids !== "") {
        		ids = JSON.parse(ids);
        	}
        	for(var key in this._changeSet.modify) {
        		var cn = this._changeSet.modify[key];
        		//更新亲的id值.
        		if(ids != null && ids !== "") {
        			var id = this.getValue(this.getOption().idkey, cn);
	        		var nid = ids[id];
	        		if(nid != null && nid !== "") {
	        			//this.setValue(this.getOption().idkey, nid);
	        			cn.data[this.getOption().idkey] = nid;
	        		}
        		}
        		cn.data.modelState = this.modelState.DEFAULT;	
				cn.data._oldValue = {};
				var op = cn.option;
				for(var nkey in op) {
					op[nkey]._pValue = null;
				}
			}
        	this._changeSet.modify = {};
        },
	    /**
	     * 获取子节点.
	     * @param index 序号
	     * @param node 节点
	     * @return 返回节点
	     */
	    getChildNode:function(index, node) {
	    	var node = node || this.curNode;
	    	if(this.isNotEmpty(this.sortFieldName) 
	    			&& node.sortIndex[this.sortFieldName] 
	    			     && this.sortType != "none") {
	    		//如果进行了排序，则获取排序中的序列号
	    		if(this.sortType == "down") {
	    			var index = node.getCount() - index - 1;
	    		}
	    		index =  node.sortNode[this.sortFieldName][index].nodeIndex;
	    	}
	    	//调用基类中的函数
	    	return this.base(index, node);
	    },
	    /**
	     * 获取子节点的序号.
	     * @param node 节点
	     * @return 返回序号
	     */
	    getChildIndex:function(node) {
	    	var node = node || this.curNode;
	    	if(node.level >= 0 && this.isNotEmpty(this.sortFieldName) 
	    			&& node.pNode.sortIndex[this.sortFieldName] && this.sortType != "none") {
	    		//如果进行了排序，则获取排序中的序列号
	    		var index = node.pNode.sortIndex[this.sortFieldName][node.index];
	    		if(this.sortType == "down") {
	    			var index = node.pNode.getCount() - index - 1;
	    		}
	    		return index;
	    	} else {
	    		//返回默认的序号
	    		return node.index;
	    	}
	    },
	    /**
	     * 设置行数据.
	     * @param rowid 行ID
	     * @param data 数据
	     * @param clazz 类名
	     * @param compareFunc 函数
	     */
	    setRowData:function(rowid, data, clazz, compareFunc) {
	    	if (data){
	    		var dataModel = this.getDataSource().getDataModel();
				var oldData = this.curNode.data;
				var index = this._getDataIndex(this.curNode.data);
				data = this.extend(true, {}, oldData, data);
				dataModel.get(this.getName() + "[" + index + "]").value(data);
				dataModel = null;
				oldData = null;
			}
	    },
	    /**
	     * 设置名称转换列表.
	     * @param fieldName 字段名称
	     * @param idNameJson 名称转换列表
	     */
	    setTransIDName:function(fieldName, idNameJson) {
	    	this.transIDName[fieldName] = idNameJson;
	    	this.transIndex++;
	    },
	    /**
	     * 获取名称转换列表.
	     * @param fieldName 字段名称
	     * @return 返回列表
	     */
	    getTransIDName:function(fieldName) {
	    	return this.transIDName[fieldName];
	    },
	    /**
	     * 添加名称转换列表.
	     * @param fieldName 字段名称
	     * @param idNameJson 名称列表
	     */
	    addTransIDName:function(fieldName, idNameJson, idKey, capKey) {
	    	if(idNameJson == null) return false;
	    	var inj = {};
	    	if(idKey == null) {
    			idKey = "id";
    		}
    		if(capKey == null) {
    			capKey = "text";
    		}
	    	if(this.isArray(idNameJson)) {	    		
	    		for(var i = 0, len = idNameJson.length; i < len; i++) {
	    			var cn = idNameJson[i];
	    			var val = cn[idKey];
	    			var txt = cn[capKey];
	    			inj[val] = txt;
	    		}
	    	} else {
	    		if(idNameJson[idKey] != null && idNameJson[capKey] != null) {
	    			inj[idNameJson[idKey]] = idNameJson[capKey];
	    		} else {
	    		    inj = idNameJson;
	    		}
	    	}
	    	var ojs = this.transIDName[fieldName];
	    	if(ojs == null) {
	    		this.transIDName[fieldName] = inj;
	    	} else {
	    		for(var key in inj) {
	    			ojs[key] = inj[key];
	    		}
	    	}
	    	ojs = null;
	    	inj = null;
	    },
	    /**
	     * 添加节点.
	     * @param records 明细
	     * @param pNode 父节点
	     */
	    append:function(records, pNode, callBack) {
	    	if(pNode == null) {
	    		if(this.getRecordCount() == 0) {
	    			pNode = this.rootNode;
	    		} else if(this.curNode.level >= 0) {
	    		    pNode = this.curNode.pNode;
	    		} else {
	    			pNode = this.curNode;
	    		}
	    	}
    		//调用添加函数
    		if(this.isArray(records)) {
    		    this.appendItemList(records, pNode, false, callBack);
    		} else {
    			this.appendChildItem(records, pNode, false);
    		}
//    		if(this.isNotEmpty(pNode.sortState)) {
//	    		for(var fn in pNode.sortState) {
//	    			var sid = pNode.sortIndex[fn];
//	    			var snd = pNode.sortNode[fn];
//	    			if(snd == null || sid == null) {
//	    				continue;
//	    			}
//	    			nodeIndex = pNode.getCount() - 1;
//	    			var nn = {"nodeIndex":nodeIndex, "nodeValue":""};
//	    			snd.splice(nodeIndex, 0, nn);
//	    			sid[nodeIndex] = nodeIndex;
//	    		}
//	    	}
	    	if(this.getCurNode().level < 0) {
	    		this.first();
	    	}
	    },
	    /**
	     * 添加子节点.
	     * @param records 明细
	     * @param pNode 父节点
	     */
	    appendChild:function(records, pNode, callBack) {
	    	if(pNode == null) {
	    		if(this.getRecordCount() == 0) {
	    			pNode = this.rootNode;
	    		} else {
	    		    pNode = this.curNode;
	    	    }
	        }
    		//调用添加函数
    		if(this.isArray(records)) {
    		    this.appendItemList(records, pNode, false, callBack);
    		} else {
    			this.appendChildItem(records, pNode, false);
    		}
//    		if(this.isNotEmpty(pNode.sortState)) {
//	    		for(var fn in pNode.sortState) {
//	    			var sid = pNode.sortIndex[fn];
//	    			var snd = pNode.sortNode[fn];
//	    			nodeIndex = pNode.getCount() - 1;
//	    			var nn = {"nodeIndex":nodeIndex, "nodeValue":""};
//	    			snd.splice(nodeIndex, 0, nn);
//	    			sid[nodeIndex] = nodeIndex;
//	    		}
//	    	}
	    	if(this.getCurNode().level < 0) {
	    		this.first();
	    	}
	    },
	    /**
	     * 添加数据.
	     * @name appendItemList
	     * @param {Array} itemList 数据
	     * @param {treeNode} pNode 父节点
	     * @param {string} newCode 新编码
	     * @param {function} callBack 回调整事件 
	     */
	    appendItemList:function(itemList, pNode, newCode, callBack) {
	    	this.transState = {};
	    	this.base(itemList, pNode, newCode, callBack);
	    	if(this.getCurNode().level < 0) {
	    		this.first();
	    	}
	    },
	    /**
	     * 插入数据.
	     * @name appendItemList
	     * @param {number} index 序号
	     * @param {Array} itemList 数据
	     * @param {treeNode} pNode 父节点
	     * @param {string} newCode 新编码
	     * @param {function} callBack 回调整事件 
	     */	    
	    insertItemList:function(index, itemList, pNode, newCode, callBack) {
	    	this.transState = {};
	    	this.base(index, itemList, pNode, newCode, callBack);
	    	if(this.getCurNode().level < 0) {
	    		this.first();
	    	}
	    },
	    /**
	     * 添加数据.
	     * @name appendChildItem
	     * @param {object} item 数据
	     * @param {treeNode} pNode 父节点
	     * @param {string} newCode 新编码
	     */
	    appendChildItem:function(item,  pNode, newCode) {
	    	this.transState = {};
	    	this.base(item,  pNode, newCode);
	    	this.caculateSum();
	    	if(this.getCurNode().level < 0) {
	    		this.first();
	    	}
	    },
	    insertChildItem:function(isindex, item, pNode, newCode) {
	    	this.transState = {};
	    	this.base(isindex, item,  pNode, newCode);
	    	this.caculateSum();
	    	if(this.getCurNode().level < 0) {
	    		this.first();
	    	}
	    },
	    /**
	     * 删除节点.
	     * @param node 节点
	     */
	    delRecord:function(node) {
	    	if(node == null) {
	    		node = this.curNode;
	    	}
	    	var pNode = node.pNode;

	    	var index = node.index;
	    	var sortIndex = 0;
	    	//删除时合计要去掉
	    	if(this.sumList != null) {
				for(var key in this.sumList) {
					this.setValue(key, 0, node);
				}
			}
	    	//先缓存序号值.
	    	if(pNode != null && this.isNotEmpty(pNode.sortState)) {
	    		for(var fn in pNode.sortState) {
	    			if(pNode.sortState[fn] === true) {
		    			var sid = pNode.sortIndex[fn];
		    			if(sid != null) {		    			
		    			    sortIndex = sid[index];
		    			}
	    			}
	    		}
	    	}
	    	var re = this.deleteItem(node);
	    	if(re === true && this.curNode.level == null) {
    			sortIndex --
		    	if(sortIndex < 0) {
		    		sortIndex = 0;
		    	}
	    		if(pNode.getCount() > 0) {
	    		    this.select(this.getChildNode(sortIndex, pNode));
	    		} else {
	    			this.select(pNode);
	    		}
	    	}
	    	return re;
	    },
	    /**
	     * 获取明细数量.
	     * @return 数量
	     */
	    getRecordCount:function() {
	    	return this.getAllCount();
	    },
	    /**
	     * 获取只读状态.
	     * @param node 节点
	     * @return 返回状态
	     */
	    getReadOnly:function(node) {
	    	if(node == null) {
	    		node = this.curNode;
	    	}
	    	return node.readOnly == null? false:node.readOnly;
	    },
	    /**
	     * 设置只读.
	     * @param value 状态
	     * @param node 节点.
	     */
	    setReadOnly:function(value, node) {
	    	if(node == null) {
	    		node = this.curNode;
	    	}
	    	node.readOnly = value;
	    },
	    /**
	     * 清空.
	     */
	    empty:function(saveOption) {
	    	this.selectFilterList = {};
	    	this.filterList = {};
	    	this.transState = {};
	    	if(saveOption != true) {
	    		//字段属性对象
		        this.fieldOption = {};	    	
		        //名称ID转换对象
		        this.transIDName = {};
	    	}
	    	this.base();
	    	this.mdm = null;
	    	this.displayModel = null;	    	
	    },
	    /**
	     * 定位.
	     * @param fieldName 字段名称
	     * @param text 字符串
	     * @param full 全匹配
	     * @return 返回
	     */
	    locate:function(fieldName, text, full, checkCrt) {
	    	return this.base(text, fieldName, full, checkCrt);
	    },
	    /**
	     * 二分查找.
	     * @param nodeAry 数组
	     * @param value 值
	     * @return 返回序号
	     */
	    _dvFind:function(nodeAry, value, dataType) {
	    	this.logInfo("_dvFind:" + value);
	    	var l = 0, h = nodeAry.length - 1, cv, ci;
	    	if(this.compare(value, nodeAry[l].nodeValue, this.sortCach, dataType) < 0) {
	    	//if(value < nodeAry[l].nodeValue) {
	    		return l;
	    	}
	    	//循环判断中间值，并决定下一回定位部份
	    	while(l < h - 3) {
	    		ci = parseInt((l + h)/2, 10);
	    		cv = nodeAry[ci].nodeValue;
	    		var cpv = this.compare(value, cv, this.sortCach, dataType);
	    		if(cpv > 0) {
	    			l = ci + 1;
	    		} else if(cpv < 0){
	    			h = ci - 1;
	    		} else {
	    			return ci;
	    		}
	    	}
	    	//少于3个时直接循环
	    	for(var i = l; i <= h; i++) {
	    		cv = nodeAry[i].nodeValue;
	    		if(this.compare(value, cv, this.sortCach, dataType) <= 0) {
	    		//if(value <= cv) {
	    			ci = i;
	    			break;
	    		}
	    		//当刚好全大于这剩下的三个时 ci没有重新定序号.
	    		ci = i + 1;
	    	}
	    	return ci;
	    },
	    /**
	     * 排序并放入一个数组中.
	     * @param fieldName 字段名称
	     * @param pNode 父节点.
	     */
	    _sortToAnAry:function(fieldName, pNode) {
	    	var i = pNode.getCount() - 1;
	    	//获取数组，并定义堆栈
	    	var curAry = pNode.sortNode[fieldName];
	    	var top = curAry.length - 1;
	    	var aryStack = [];
	    	var topStack = [];
	    	var sortAry = [];
	    	var sortIndexAry = {};
	    	//循环处理
	    	while(i >= 0) {
	    		if(top >= 0) {
	    			//如果栈中有数据
	    			if(curAry[top].cnode.length > 0) {
	    				//如果带子节点
	    				sortIndexAry[curAry[top].nodeIndex] = i;
	    				sortAry[i--] = curAry[top];
	    				//把当前节点入栈
		    			aryStack.push(curAry);
			    		topStack.push(top - 1);
			    		//定位到子节点中
		    			curAry = curAry[top].cnode;
		    			top = curAry.length - 1;
		    		} else if(top >= 0){	
		    			//如果没有子节点，则拉直数组
		    			sortIndexAry[curAry[top].nodeIndex] = i;
		    		    sortAry[i--] = curAry[top];
		    		    top--;
		    		}
	    		} else {
	    			//出栈
	    			curAry = aryStack.pop();
	    			top = topStack.pop();
	    		}
	    	}
	    	//设置把序结果
	    	pNode.sortNode[fieldName] = sortAry;
	    	pNode.sortIndex[fieldName] = sortIndexAry;
	    },
	    /**
	     * 值插入到排序列表中.
	     * @param fieldName 字段名称
	     * @param pNode 父节点
	     * @param cIndex 序号
	     * @param cValue 新值
	     */
	    _insertToSortList:function(fieldName, pNode, cIndex, cValue, dataType) {
	    	if(pNode.sortNode[fieldName].length == 0) {
	    		//第一个节点直接生成
	    		pNode.sortNode[fieldName] = [{"nodeValue":cValue,"nodeIndex":cIndex, "cnode":[]}];
	    	} else {
		    	pAry = pNode.sortNode[fieldName];
		    	var len = pAry.length;
		    	if(this.compare(cValue, pAry[len - 1].nodeValue, this.sortCach, dataType) >= 0) {
		    	//if(cValue >= pAry[len - 1].nodeValue) {
		    		//如果在当前数组中最大，直接添加到数组后
		    		pAry.push({"nodeValue":cValue,"nodeIndex":cIndex,"cnode":[]});
		    	} else {
		    		//如果不是最大，则添加到比当前小的节点子节点
			    	var index = this._dvFind(pAry, cValue, dataType);
			    	pAry = pAry[index].cnode;
			    	len = pAry.length;
			    	var hasPush = false;
			    	//循环查找定位
			    	while (len > 0) {
			    		if(this.compare(cValue, pAry[len - 1].nodeValue, this.sortCach, dataType) >= 0) {
				    	//if(cValue >= pAry[len - 1].nodeValue) {
				    		pAry.push({"nodeValue":cValue,"nodeIndex":cIndex,"cnode":[]});
				    		hasPush = true;
				    		break;
				    	} else {
			    		    index = this._dvFind(pAry, cValue, dataType);
			    		    pAry = pAry[index].cnode;
			    		    len = pAry.length;
				    	}
			    	}
			    	if(!hasPush) {
			    		//添加到数组上
				    	pAry.push({"nodeValue":cValue,"nodeIndex":cIndex,"cnode":[]});
				    }
		    	}
	    	}
	    },
	    /**
	     * 异步排序处理.
	     * @param fieldName 字段
	     * @param node 节点
	     * @param cNode 子节点
	     * @param limitCount 限制数量
	     * @param callBack 回调
	     */
	    _asynSortNode:function(fieldName, node, cNode, limitCount, callBack) {
	    	this.logInfo("_asynSortNode:" + fieldName);
	    	if(this.getAllCount() > 0) {
		    	if(node == null) {
		    		node = this.rootNode;
		    	}
		    	if(cNode == null) {
		    		cNode = this.getChildNode(0, node);//node.cNode[0];
		    	}
		    	var ui = this.beginUpdate(true);
		    	this.select(cNode);
		    	this.logInfo("_asynSortNode:" + cNode.scrIndex);
		    	var dt = this.getDataType(fieldName);
		    	var i = 0;
		    	//循环处理排序
		    	while(!this.isEof() && this.getLevel() > node.level && i < limitCount) {
		    		var cNode = this.getCurNode();
		    		var pNode = cNode.pNode;
		    		if(!pNode.sortState[fieldName] || pNode.sortChanged[fieldName] == true) {
		    			if(cNode.index == 0) {
		    				pNode.sortNode[fieldName] = [];
		    			}
		    			var cv;
		    			//取当前值
		    			if(dt == "number" || dt == "money") {
		    				cv = this.getValue(fieldName, cNode);
		    			} else {		    			
		    			    cv = this.getDisplay(fieldName, undefined, cNode);
		    			}
		    			//调用插入序列函数
		    		    this._insertToSortList(fieldName, pNode, cNode.index, cv, dt);		    		
			    		if(cNode.index == pNode.getCount() - 1) {
			    			//如果是某节点的最后一个子节点，则拉值
			    			pNode.sortState[fieldName] = true;
			    			pNode.sortChanged[fieldName] = false;
			    			this._sortToAnAry(fieldName, pNode);
			    		}
		    		}
		    		this.next(true);
		    		i++;
		    	}
		    	this.endUpdate(false, ui);
		    	if(!this.isEof() && this.getLevel() > node.level) {
		    		//如果没有处理完，则异步再调用
		    		var _this = this;
		    		cNode = this.getCurNode();
		    		setTimeout(function(){_this._asynSortNode(fieldName, node, cNode, limitCount, callBack); _this = null}, 10);
		    	} else {		    		
		    		//回调函数
		    		if(typeof callBack == "function") {
		    		    callBack.apply(this);
		    		}
		    	}
	    	} else {
	    		if(typeof callBack === "function") {
	    			callBack.apply(this);
	    		}
	    	}
	    },
	    /**
	     * 处理排序.
	     * @param fieldName 字段
	     * @param sortType 排序类型
	     * @param callBack 回调
	     */
	    doSort:function(fieldName, sortType, callBack) {
	    	var _this = this;
	    	this.logBegin("doSort");
	    	this.sortFieldName = null;
	    	//调用排序异步处理函数
	    	this._asynSortNode(fieldName, undefined, undefined, 100, function(){
	    		_this.sortFieldName = fieldName;
	    		_this.sortType = sortType;
	    		_this.logEnd("doSort");	    
	    		//处理回调函数
	    		if(typeof callBack == "function") {
	    			callBack.apply(this);
	    		}
	    	});
	    },
	    /**
	     * 清空过滤条件.
	     */
	    _emptyFilterItem:function() {
	    	this.filterStack = [];
	    	this.selectFilterList = {};
	    	this.topFilterItem = null;
	    },
	    /**
	     * 添加一个过滤项目
	     * {"fieldName":fieldName, "all":all, "sel":sel}
	     * @param {json} filterItem 过滤项目.
	     */
	    _pushFilterItem:function(filterItem) {
	    	this.filterStack.push(filterItem);
	    	this.topFilterItem = filterItem;
	    },
	    /**
	     * 取出一个过滤项目
	     */
	    _popFilterItem:function() {
	    	if(this.filterStack.length > 0) {
	    	    this.filterStack.pop();
	    	}
	    	this.topFilterItem = this._getLastFilterItem();	
	    	//还原到上一次过滤
	    	if(this.topFilterItem != null) {
		    	this.filterFieldName = this.topFilterItem.fieldName;
		    	this.filterList[this.filterFieldName] = this.topFilterItem.all;
		    	this.selectFilterList = this.topFilterItem.sel;
	    	}
	    },
	    _setFilterChangedState:function(fieldName, oldValue, newValue) {
	    	var len = this.filterStack.length;
	    	if(len > 0) {
		    	var ov = null, nv = null;
		    	
		    	for(var i = 0; i < len; i++) {
		    		var item = this.filterStack[i];		    		
		    		if(item.fieldName == fieldName) {
		    			if(ov == null) {
			    			ov = this.getDisplay(fieldName, oldValue);
			    			nv = this.getDisplay(fieldName, newValue);
			    		}
		    			if(item.all != null && item.all[oldValue] != null) {
		    				delete item.all[oldValue];
		    			}
		    			item.all[newValue] = nv;
		    			if(item.sel[ov] != null) {
		    				delete item.sel[ov];
		    			}
		    			item.sel[nv] = 1;
		    		}
		    		item = null;
		    	}
	    	}
	    },
	    /**
	     * 获取最上面的过滤对象.
	     */
	    _getLastFilterItem:function() {
	    	if(this.filterStack.length > 0) {
	    	    return this.filterStack[this.filterStack.length - 1];
	    	} else {
	    		return null;
	    	}
	    },
	    /**
	     * 获取当前行的过滤状态.
	     */
	    _getFilterState:function(node) {
	    	if(node == null) {
	    		node = this.curNode;
	    	}
	    	var state = true;
	    	for(var i = 0, len = this.filterStack.length; i < len && state; i++) {
	    		var item = this.filterStack[i];
	    		if(item == null || item.fieldName == null || item.fieldName === "") {
	    			continue;
	    		}
	    		var sel = item.sel;
	    		var val = this.getDisplay(item.fieldName, undefined, node);
	    		var val2 = this.getValue(item.fieldName, node);
	    		//添加默认空白符
	    		if(val === "") {
	    			val = this.getI18n("qzz.filterEmpty","(空白)");
	    		}
	    		if(sel[val] == null && sel[val2] == null) {
	    			state = false;
	    		}
	    		item = null;
	    	}
	    	return !state;
	    },  
	    /**
	     * 是否过滤字段
	     */
	    getFilterState:function(fieldName) {
	    	var state = true;
	    	for(var i = 0, len = this.filterStack.length; i < len && state; i++) {
	    		var item = this.filterStack[i];
	    		if(item.fieldName == fieldName) {
	    			state = false;
	    		}
	    		item = null;
	    	}
	    	return !state;
	    },
	    //
	    /**
	     * 收集某行的数据列表.
	     */
	    _asynCollectNode:function(fieldName, node, cNode, limitCount, callBack) {
	    	this.logInfo("_asynCollectNode:" + fieldName);
	    	if(this.getAllCount() > 0) {
		    	if(node == null) {
		    		node = this.rootNode;
		    	}
		    	if(cNode == null) {
		    		cNode = this.getChildNode(0, node);//node.cNode[0];
		    	}
		    	var tmpNode = this.getCurNode();
		    	var ui = this.beginUpdate(true);
		    	this.select(cNode);
		    	var i = 0;
		    	if(this.isEmpty(this.filterList[fieldName])) {
		    		this.filterList[fieldName] = {};
		    	}
		    	while(!this.isEof() && i < limitCount && this.getLevel() > node.level) {
		    		var vl = this.getValue(fieldName);
		    		var text = this.getDisplay(fieldName);
		    		if(text !== "") {
		    		    this.filterList[fieldName][vl] = text;
		    		} else {
		    			this.filterList[fieldName][vl] = this.getI18n("qzz.filterEmpty", "(空白)");
		    		}
		    		this.next(true);
		    		i++;
		    	}
		    	if(!this.isEof() && this.getLevel() > node.level) {
		    		var _this = this;
		    		cNode = this.getCurNode();
		    		this.select(tmpNode);
		    		this.endUpdate(false, ui);
		    		setTimeout(function(){_this._asynCollectNode(fieldName, node, cNode, limitCount, callBack); _this = null;}, 10);
		    	} else {
		    		this.select(tmpNode);
		    		this.endUpdate(false, ui);
		    		if(typeof callBack === "function") {
		    			callBack.apply(this);
		    		}		    		
		    	}
	    	} else {
	    		if(typeof callBack === "function") {
	    			callBack.apply(this);
	    		}
	    	}
	    },
	    /**
	     * 异步收集数据.
	     * fieldName 字段名称
	     * callBck 回调函数
	     */
	    collectFilter:function(fieldName, callBack) {
	    	var lastItem = this._getLastFilterItem();
	    	if(lastItem == null || fieldName !== lastItem.fieldName) {
	    		if(this.hasbind("onCollectFilter")) {
	    			var _this = this;
	    			this.trigger("onCollectFilter",[this.filterStack, fieldName, function(filterList){
	    				_this.filterList[fieldName] = filterList;
	    				if(typeof callBack === "function") {
	    		    		callBack.apply(this);
	    		    	}
	    			}])
	    		} else {
		    		this.filterList[fieldName] = {};
		    		this._asynCollectNode(fieldName, undefined, undefined, 500, callBack);
	    		}
	    	} else if(typeof callBack === "function") {
	    		callBack.apply(this);
	    	}
	    },
	    /**
	     * 执行过滤.
	     */
	    doFilterCompare:function(dataSet) {
	    	
	    },
	    /**
	     * 执行过滤.
	     * @name setFiltered
	     * @param filtered 执行过滤
	     * @param callBack 回调函数
	     */
	    setFiltered:function(filtered, callBack) {
	    	var _this = this;
	    	if(filtered) {
	    		//添加过滤项目.
	    		if(this.isNotEmpty(this.selectFilterList)
	    				&& (this.topFilterItem == null 
	    				    || this.topFilterItem.fieldName != this.filterFieldName)) {
	    			//与顶层的过滤不一样时才加入
		    		this._pushFilterItem({"fieldName":this.filterFieldName, 
		        		"all":this.filterList[this.filterFieldName],
		        		    "sel":this.selectFilterList});
	    		}
	    		if(this.hasbind("onServerFilter")) {
	    			this.trigger("onServerFilter",[filtered, this.filterStack, callBack]);
	    		} else {
		    		//执行过滤
			        this.doFilter(function() {
			        	_this.first();
			        	_this.getCurNode().scrIndex = 1;		        	
			        	if(typeof callBack === "function") {
			        	    callBack();	
			        	}
			        });
	    		}
	    	} else {
	    		if(this.hasbind("onServerFilter")) {
	    			this.trigger("onServerFilter",[filtered, this.filterStack, callBack]);
	    		} else {
		    		this._asynResetFilterNode(undefined, undefined, 1000, true, function() {
		    			_this.filtered = false;
		    			_this.first();
		    			if(typeof callBack === "function") {
			        	    callBack();	
			        	}
		    			
		    		});
	    		}
	    	}
	    },
	    getTopFilterName:function() {
	    	if(this.topFilterItem == null) {
	    		return "";
	    	} else {
	    		return this.topFilterItem.fieldName;
	    	}
	    },
	    /**
	     * 添加过滤字段.
	     */
	    addFilterText:function(fieldName, selItem, callBack) {
	    	if(this.topFilterItem != null 
        			&& this.topFilterItem.fieldName == fieldName) {
    			this._popFilterItem();		        			
    		}
	    	if(this.isArray(selItem)) {
	    		//this.selectFilterList = {};
	    		var silen = selItem.length;
	    		if(silen > 0 && selItem[0].id !== "all") {
	    			//置空了就不能联动多列筛选，不知道什么场景下会清除所有的筛选选项
	    			//this._emptyFilterItem();
	    			this.selectFilterList = {};
		    		var i = 0;
		    		for(; i < silen - 1; i++) {
	        	    	this._addFilterText(fieldName, selItem[i].text, false);
	   	        	}
	        	    this._addFilterText(fieldName, selItem[i].text, true, callBack);
	    		} else {
	    			if(this.topFilterItem == null) {
	        			this.clearFilterText(callBack);
	        		} else {
		        		this.setFiltered(true, callBack);		
	        		}
	    		}
	    	} else if(typeof selItem == "string") {
	    		this._addFilterText(fieldName, selItem, true, callBack)
	    	} else if(selItem.text != null && selItem.text !== "") {
	    		this._addFilterText(fieldName, selItem.text, true, callBack)
	    	}
	    },
	    /**
	     * 添加过滤字符串.
	     */
	    _addFilterText:function(fieldName, text, filter, callBack) {
	    	if(this.filterFieldName !== fieldName) {
	    		this.selectFilterList = {};
	    		this.filterFieldName = fieldName;
	    	}
	    	this.selectFilterList[text] = 1;
	    	if(filter !== false) {
	    	    this.setFiltered(true, callBack);
	    	} else if(typeof callBack === "function") {
	    	    callBack()
	    	}
	    },
	    /**
	     * 异步获取某字段的最大字符串.
	     * @name _asynCallFunc
	     */
	    _asynCallFunc:function(params, node, cNode, limitCount, doInitFunc, doEachFunc, callBack) {
	    	this.logInfo("_asynCallFunc:");
	    	if(node == null) {
	    		node = this.rootNode;
	    	}
	    	if(cNode == null) {
	    		cNode = this.getChildNode(0, node);//node.cNode[0];
	    	}
	    	if(typeof doInitFunc === "function") {
	    		doInitFunc(node, cNode);
	    	}
	    	var tmpNode = this.getCurNode();
	    	var needRun = typeof doEachFunc === "function";
	    	if(needRun) {		    	
		    	var ui = this.beginUpdate(true);
		    	this.select(cNode);
		    	var i = 0;	    	
		    	var priorNode = null;
		    	while(!this.isEof() && i < limitCount && this.getLevel() > node.level) {	 
		    		var cNode = this.getCurNode();
		    		doEachFunc(this, params, cNode, priorNode);
		    		//先移动到下一个节点.
		    		this.next();		    		   		
		    		i++;
		    	}
		    	priorNode = cNode;
		    	cNode = this.getCurNode();
	    	}
	    	if(needRun && !this.isEof() && this.getLevel() > node.level) {
	    		this.select(tmpNode);
	    		this.endUpdate(false, ui);
	    		var _this = this;		    		
	    		setTimeout(function(){_this._asynCallFunc(params, node, cNode, limitCount, doInitFunc, doEachFunc, callBack); _this = null;}, 10);
	    	} else {
	    		this.select(tmpNode);
	    		this.endUpdate(false, ui);
	    		if(typeof callBack === "function") {
	    			callBack.apply(this);
	    		}
	    	}	
	    },
	    initMaxText:function() {
	    	this.maxText = {};
		    this.maxTextLen = {};
		    this.maxCapWidth = {};
		    this.maxLevel = 0;
	    },
	    /**
	     * 获取最长的字符串.
	     * @name getMaxText
	     * @param fieldNames
	     * @param callBack
	     */
	    getMaxText:function(fieldNames, callBack, cach) {
	    	if(typeof fieldNames == "string") {
	    		fieldNames = [fieldNames];
	    	}
	    	var limitCount = 100;
	    	if(this.isArray(fieldNames) && fieldNames.length > 0) {
	    		if(cach === true) {
	    			var re = true;
	    			for(var j = 0, fdlen = fieldNames.length; re && j < fdlen; j++) {
	    				if(this.maxText == null || this.maxText[fieldNames[j]] == null) {
	    					re = false;
	    				}
	    			}
	    			if(re == true) {
	    				if(typeof callBack == "function") {
		    				callBack(fieldNames, this.maxText);
		    			} 
	    				return;
	    			}
	    		}
	    		limitCount = parseInt(limitCount / fieldNames.length, 10);
	    		if(this.isEmpty(this.maxText)) {
	    		    this.initMaxText();
	    		}
	    		var cacFns = [];
	    		for(var j = 0, fdlen = fieldNames.length; j < fdlen; j++) {
	    			var fn = fieldNames[j];
	    			if(this.maxText[fn] == null) {
		    			this.maxText[fn] = "";
		    			this.maxTextLen[fn] = 0;
		    			cacFns.push(fn);
	    			}
	    		}
	    		var _this = this;
	    		//异步调用
	    		this._asynCallFunc(cacFns, undefined, undefined, limitCount, 
		    		//初始化函数体
		    		undefined, 
		    		//循环体
		    		function(dataSet, cacFns, cNode, priorNode){
		    			for(var j = 0, fdlen = fieldNames.length; j < fdlen; j++) {
		    				var fn = fieldNames[j];
		    				var curText = dataSet.getDisplay(fn);
		    				if(typeof curText === "string" && curText.indexOf("<") != -1) {
							    curText = curText.replace(/<(\/)?(a|span|div|li|ul|table|tr|td|input|font)( [^<>]+)?>/gi,"");
							}
		    				var curLen = dataSet.strLen(curText);
		    				if(curLen > dataSet.maxTextLen[fn]) {
		    					dataSet.maxTextLen[fn] = curLen;
		    					dataSet.maxText[fn] = curText;
		    				}
		    			}
		    			if(cNode.level > dataSet.maxLevel) {
		    				dataSet.maxLevel = cNode.level;
		    			}
		    		}, 
		    		//回调函数体
		    		function() {
		    			if(typeof callBack == "function") {
		    				callBack(fieldNames, _this.maxText);
		    			} 	    			
		    		}
	    		);
	    	}	    	
	    },
	    /**
	     * 删除过滤字符串.
	     * @param fieldName 字段名称,
	     * @param text 文本
	     * @param filter 执行过滤
	     */
	    delFilterText:function(fieldName, text, filter) {
	    	//只处理字段一样的
	    	if(this.filterFieldName === fieldName) {
	    		//只处理有数据的
	    		if(this.isNotEmpty(this.selectFilterList[text])) {
	    		    delete this.selectFilterList[text];	    		    
	    		    if(filter !== false) {
	    		    	//判断有没有数据.
		    		    if(this.isNotEmpty(this.selectFilterList)) {
		    		        this.setFiltered(true);
		    		    } else {
		    		    	this.setFiltered(false);
		    		    }
	    		    }
	    		}	    		
	    	}
	    },
	    /**
	     * 清除过滤.
	     */
	    clearFilterText:function(callBack) {
	    	if(this.filtered) {
	    		this._emptyFilterItem();
		    	this.setFiltered(false, callBack);
	    	} else if(typeof callBack == "function") {
	    		callBack();
	    	}
	    },
	    /**
	    * 异步生成索引对象.
	    * @param fieldName 字段
	    * @param node 起始节点
	    * @param cNode 当前节点
	    * @param limitCount 分批执行次数
	    * @param callBack 回调函数
	    */     
	    _asynSetKeyNode:function(fieldName, node, cNode, limitCount, callBack) {
	    	this.logInfo("_asynSetKeyNode:" + fieldName.join(this.valueSplit));
	    	if(node == null) {
	    		node = this.rootNode;
	    	}
	    	if(cNode == null) {
	    		cNode = this.getChildNode(0, node);//node.cNode[0];
	    	}
	    	var tmpNode = this.getCurNode();
	    	var ui = this.beginUpdate(true);
	    	this.select(cNode);
	    	var i = 0;
	    	var flen = fieldName.length;
	    	while(!this.isEof() && i < limitCount && this.getLevel() > node.level) {
	    		var valueKey = [];
	    		for(var j = 0; j < flen; j++) {
	    			valueKey[j] = this.getValue(fieldName[j]);
	    		}
	    		var vl = fieldName.join(this.fieldSplit) + this.valueSplit + valueKey.join(this.fieldSplit);
	    		this.keyNodeJson[vl] = this.getCurNode();
	    		this.next(true);
	    		i++;
	    	}
	    	cNode = this.getCurNode();
	    	if(!this.isEof() && this.getLevel() > node.level) {
	    		this.select(tmpNode);
	    		this.endUpdate(false, ui);
	    		var _this = this;		    		
	    		setTimeout(function(){_this._asynSetKeyNode(fieldName, node, cNode, limitCount, callBack); _this = null;}, 10);
	    	} else {
	    		this.select(tmpNode);
	    		this.endUpdate(false, ui);
	    		if(typeof callBack === "function") {
	    			callBack.apply(this);
	    		}
	    	}	
	    },
	    /**
	     * 生成keyJson.
	     * @param keyName 字段名称.
	     */
	    setPKeyName:function(keyName, callBack) {
	    	var keyStr = keyName;
	    	if(typeof keyName == "string") {
	    		keyName = keyName.split(this.fieldSplit);
	    	} else if(this.isArray(keyName)) {
	    		keyStr = keyName.join(this.fieldSplit);
	    	} else {
	    		if(typeof callBack === "function") {
	    			callBack.apply(this);
	    		}
	    		return false;
	    	}
	    	var len = this.PKeyName.length;
	    	var has = false;
	    	for(var i = 0; i < len; i++) {
	    		if(this.PKeyName[i] === keyStr) {
	    			has = true;
	    			break;
	    		}
	    	}
	    	if(!has) {
		    	this.PKeyName.push(keyStr);
		    	this._asynSetKeyNode(keyName, undefined, undefined, 1000, callBack);
	    	} else {
	    		if(typeof callBack == "function") {
	    			callBack.apply(this);
	    		}
	    	}
	    },
	    /**
	     * 返回索引指定行节点.
	     */
	    getKeyNode:function(keyName, keyValue) {	
	    	var node = null;
	    	if(typeof keyName === "string") {
	    		node = this.keyNodeJson[keyName + this.valueSplit + keyValue];
	    	} else if(this.isArray(keyName) && this.isArray(keyValue)) {
	    		node = this.keyNodeJson[keyName.join(this.fieldSplit) + this.valueSplit + keyValue.join(this.fieldSplit)];
	    	}
	    	return node;
	    },
	    /**
	     * 设置运算公式.
	     * @param fieldName 字段
	     * @param expression 表达式
	     */
	    addExpress:function(fieldName, keyFieldName, value, expression) {
	    	this.setPKeyName(keyFieldName, function() {
	    		var node = this.getKeyNode(keyFieldName, value);
	    		if(node != null) {
		    		var exp = new qzz.expression();
			    	exp.setDataSet(this);
			    	exp.setExpression(fieldName, keyFieldName, value, expression);			    	
			    	this.getCellOption(fieldName, node).title = exp.caption;
			    	node = null;
			    	//与原来的判断优先级，并插入队列中.
			    	var len = this.expList.length;
			    	if(len === 0) {
			    		this.expList.push(exp);
			    	} else {
			    		var i = 0;
			    		for(i = 0; i < len; i++) {
			    			var ce = this.expList[i];
			    			var index = ce.indexOf(exp.fieldName, exp.keyFieldName, exp.keyValue);
			    			if(index >= 0) {
			    				break;
			    			}
			    			ce = null;
			    		}  
			    		this.expList.splice(i, 0, exp);
			    	}
		    	} else {
		    		this.logInfo("can not found cell ("+fieldName+","+keyFieldName + "_" + value + ")");
		    	}
	    	});	    	
	    },
	    /**
	     * 清除表达式.
	     */
	    clearExpress:function() {
	    	 this.expList = [];
	    },
		/**
		 * 公式运算.
		 */
		caculate:function(full) {
			var len = this.expList.length;
			for(var i = 0; i < len; i++) {
				var exp = this.expList[i];
				if(exp.node == null) {
					exp.node = this.getKeyNode(exp.keyFieldName, exp.keyValue);
				}
				if(exp.node != null 
						&& (this.getCellOption(exp.fieldName, exp.node).cacState == 1 || full)) {
				    this.setValue(exp.fieldName, exp.getValue(), exp.node, true);
				    this.getCellOption(exp.fieldName, exp.node).cacState = 0;
				}
			}
		},
	    /**
	     * 添加勾J公式.
	     */
	    addGJExpress:function(keyFieldName, expression) {
	    	 if(expression == null) {
	    		 expression = keyFieldName;
	    		 keyFieldName = null;
	    	 }
	    	 if(keyFieldName == null) {
	    		 var exp = new qzz.expression();
	    		 exp.setDataSet(this);
	    		 exp.setGJExpression(keyFieldName, expression);
	    		 this.expColGJList.push(exp);
	    	 } else {
		    	 this.setPKeyName(keyFieldName, function() {
		    		 var exp = new qzz.expression();
					 exp.setDataSet(this);
					 exp.setGJExpression(keyFieldName, expression);
					 //与原来的判断优先级，并插入队列中.
					 this.expGJList.push(exp);
			    });
	    	 }
	    },
		/**
		 * 清除表达式.
		 */
		clearGJExpress:function() {
			this.expGJList = [];
			this.expColGJList = [];
		},
	    /**
	     * 执行勾稽公式.
	     * @param control 是否强控.
	     */
	    caculateGJ:function(control, callBack) {
	    	if(typeof control == "function") {
	    		callBack = control;
	    		control = false;
	    	}
	    	var len = this.expGJList.length;
	    	var re = [];
			for(var i = 0; i < len; i++) {
				var exp = this.expGJList[i];
				if(control != true || exp.messageState == 3) {
					var reVa = exp.getValue();
				    if(this.reverGJ && reVa == true 
				    		|| this.reverGJ == false && reVa != true) {
				        re.push({
				        	"cellList":exp._expObject,
				        	"exp":exp.exp,
				        	"caption":exp.caption,
				        	"message":exp.message,
				            "sumitState":exp.sumitState,
				            "messageState":exp.messageState
				        });
				    }
				}
			}
			//列勾稽
			len = this.expColGJList.length;
			if(len > 0) {
				var me = this;
				this.each(function(node) {
					for(var i = 0; i < len; i++) {
						var exp = me.expColGJList[i];
						if(control != true || exp.messageState == 3) {
							var reVa = exp.getValue(node);
							if(me.reverGJ && reVa == true
									|| me.reverGJ == false && reVa != true) {
								re.push({
						        	"cellList":exp._expObject,
						        	"exp":exp.exp,
						        	"caption":exp.caption,
						        	"message":exp.message,
						            "sumitState":exp.sumitState,
						            "messageState":exp.messageState,
						            "node":node
						        });								
							}
						} //是否强控
					} //for
				}, function() {
					if(typeof callBack == "function") {
						callBack(re);
					}
				})
			} else {
				if(typeof callBack == "function") {
					callBack(re);
				}
			}
			return re;
        },
        /**
         * 添加合计列.
         */
        addSumColumn:function(fieldName) {
        	var len = this.sumList.length;
        	if(this.sumList[fieldName] == null) {
        		this.sumList[fieldName] = 0;
        	}
        },
    	/**
    	 * 清除表达式.
    	 */
    	clearSumColumn:function() {
    		this.sumList = {};
    	},
        /**
         * 顶层合计.
         * @param {boolean} full 所有列汇总
         */
	    caculateSum:function(full, fieldName, oldValue, newValue, node) {
        	var len = this.sumList.length;
        	var sums = {};
        	//初始化
        	if(node != null && node.level > 0 && this.sumAllLevel) {
        		//如果有字段名，则表示要增量合计
        		if(fieldName != null) {
        			if(this.sumList[fieldName] != null) {        				
        				var pNode = node.pNode;
        				var val = this.getValue(fieldName, pNode);
        				if(val == null || val === "") {
        					val = 0;
        				}
        				val = val + newValue - oldValue;
        				this.setValue(fieldName, val, pNode);
        			}
        		}
        	} else if(this.sumAllLevel && full != false) {
        		//全量运算
        		var cn = this.curNode;
        		var ui = this.beginUpdate(true);
        		//this.last();
        		//while(!this.isBof()) {
        			//计算合计
        		//	this.prior(true);
        		//}
        		this.curNode = cn;
        		this.endUpdate(false, ui);
        	}
        	//只计算顶层，或者全量运算
        	if(node != null && node.level == 0 || full != false) {
	        	//初始化数据
	        	for(var fieldName in this.sumList) {
	        		sums[fieldName] = 0;
	        	}
	        	//顶层合计.
	        	for(var i = 0; i < this.rootNode.getCount(); i++) {
	        		var node = this.rootNode.cNode[i];
	        		for(var fieldName in this.sumList) {
	        			var so = this.sumList[fieldName];
	        			if(so == 1 || full != false) {
		        			var val = this.getValue(fieldName, node);
		        			if(val == null || val === "") {
		        				val = 0;
		        			}
		        			sums[fieldName] += parseFloat(val);
	        			}
	        		}
	        	}	
	        	//更新数据到summary行.
	        	for(var fieldName in this.sumList) {
	        		var so = this.sumList[fieldName];
	    			if(so == 1 || full != false) {
	        			this.setSummary(fieldName, sums[fieldName]);
	        			this.sumList[fieldName] = 0;
	        		}
	        	}
        	}
        },
        /**
         * 重置公式。
         */
        resetExpress:function() {
        	//公式重定向.
        	var len = this.expList.length;
			for(var i = 0; i < len; i++) {
				var exp = this.expList[i];
				exp.node = this.getKeyNode(exp.keyFieldName, exp.keyValue);
				this.getCellOption(exp.fieldName, exp.node).title = exp.caption;
				exp.decode();
			}
			len = this.expGJList.length;
			for(var i = 0; i < len; i++) {
				var exp = this.expGJList[i];
				exp.decode();
			}
        },
        /**
         * 设置选择列表.
         * @param {string} keyFieldName 主键字段
         * @param {array} keyValue 选择值数组
         * @param {boolean} state 选择/不选择状态
         */
        setCheckedData:function(keyFieldName, keyValue, state) {
        	if(this.multiSelect) {
        		if(state == null) {
        			state = true;
        		}
	        	var keyJson = {};
	        	if(this.isArray(keyValue)) {
	        		for(var i = 0, len = keyValue.length; i < len; i++) {
	        			var vl = keyValue[i];
	        			keyJson[vl] = vl;
	        		}
	        	} else if(typeof keyValue == "object"){
	        		keyJson = keyValue;
	        	} else {
	        		keyJson[keyValue] = keyValue;
	        	}
	        	var cn = this.getCurNode();
	        	var ui = this.beginUpdate(true);
				this.first();
				while(!this.isEof()) {
					if(keyJson[this.getValue(keyFieldName)] != null) {
						if(state) {
							this.setSelect();
						} else {
						    this.setUnSelect();
						}
					}
					this.next(true);
				}
				this.select(cn);
				this.endUpdate(false, ui);
				cn = null;
        	}
        },
        setSelectData:function(keyFieldName, keyValue, state) {
        	this.setCheckedData(keyFieldName, keyValue, state);
        },
		 /**
		  * 返回选择的节点.
		  * @name getSelectedData
		  */
        getCheckedData:function(curOnly) {
        	 var cn = this.getCurNode();
        	 //如果没有选择则返回null
        	 if(cn.level < 0) {
        		 return null;
        	 }
			 var ui = this.beginUpdate(true);
			 var selDatas;
			 if(curOnly === true || !this.multiSelect) {
				 selDatas = this.getCurNode().data;
			 } else {
				 this.first();
				 selDatas = [];
				 while(!this.isEof()) {
					 if(this.isChecked()) {
						 selDatas.push(this.extend({}, this.getCurNode().data));
					 }
					 this.next(true);
				 }
				 this.select(cn);
			 }
			 this.endUpdate(false, ui);
			 return selDatas;
        },
		 getSelectedData:function(curOnly) {
			return this.getCheckedData(curOnly);
		 },
		 
		 /**
		  * 返回选择的节点.
		  * @name getSelectedData
		  */
		 getSelectRowIds:function(curOnly) {
			 var cn = this.getCurNode();
			 var ui = this.beginUpdate(true);			 
			 var selDatas;
			 var kn = this.keyName;
			 if(this.isArray(kn) && kn.length > 0) {
				 kn = kn[0];
			 }
			 if(curOnly === true || !this.multiSelect) {
				 selDatas = this.getValue(kn);
			 } else {
				 selDatas = [];
				 this.first();
				 while(!this.isEof()) {
					 if(this.isChecked()) {					 
						 selDatas.push(this.getValue(kn));
					 }
					 this.next(true);
				 }
				 this.select(cn);
			 }
			 this.endUpdate(false, ui);
			 return selDatas;
		 },
		/**
		 * 获取所有列效验不符合要求的节点.
		 */
		validateAll:function(callBack) {
			var cms = this.getOption().viewColModels;
			var me = this;
			var res = [];
			this.each(function(node) {
				for(var i = 0, len = cms.length; i < len; i++) {
					var cm = cms[i];
					var vre = this.validateValue(cm.validate, node, cm.name);
					if(vre.state !== true) {
						res.push({"node":node, "colModel":cm, "state":vre.state, 
							"message":vre.message || cm.validateMessage || cm.valiMsg || ""});
					}
				}
			}, function() {
				if(typeof callBack == "function") {
					callBack(res);
				}
			});
		},
		/**
		 * 跟据配置校验值.
		 */
		validateValue:function(validate, node, fieldName, value) {
			var show = true;
			var valiMsg = "";
			if(value == null) {
				value = this.getValue(fieldName, node);
			}
			if(/^notempty$/i.test(validate)) {
				if(value == null || value === "") {
					show = false;
					valiMsg = this.getI18n("qzz.notEmpty", "输入值不能为空") || "";
				}
			} else if(this.isNotEmpty(validate)) {				
				var hasVal = false;				
				if(/^email$/i.test(validate)) {
					if(value != null && value !== "") {
						show = this.isEmail(value);
						valiMsg = this.getI18n("qzz.emailVali", "输入的电子邮件不符合格式校验要求，请按照电子邮箱账号@邮箱域名格式输入，例如：User@ygsoft.com。");
					}
					hasVal = true;
				} else if(/^telePhone$/i.test(validate)) {
					if(value != null && value !== "") {
						show = this.isTele(value);
						valiMsg = this.getI18n("qzz.teleVali", "输入的电话号码不符合校验要求，请按照区号-电话号码-分机号格式输入，例如：010-12345678-1234。");
					}
					hasVal = true;
				} else if(/^mobileTelePhone$/i.test(validate)) {
					if(value != null && value !== "") {
						show = this.isMobile(value);
						valiMsg = this.getI18n("qzz.mobileVali", "输入的手机不符合格式校验要求，请按照电话号码（11数字位）格式输入，例如：13701234567。");
					}
					hasVal = true;
				} else if(/^postboat$/i.test(validate)) {
					if(value != null && value !== "") {
						show = this.isPostid(value);
						valiMsg = this.getI18n("qzz.postVali", "输入的邮编不符合格式校验要求，请按照邮编号码（6位数字位）格式输入，例如：519085。");
					}
					hasVal = true;
				} else if(/^idcard$/i.test(validate)) {
					if(value != null && value !== "") {
						show = this.isIDCard(value);
						valiMsg = this.getI18n("qzz.idcardVali", "输入的证件号码不符合格式校验要求，请按照身份证号（18位数字， 最后一位是数字或者字母）格式输入，列如：440401234567890123。");
					}
					hasVal = true;
				}
				if(hasVal === false) {
					var colModel = this.getColModel(fieldName);
					valiMsg = colModel.validateMessage || colModel.valiMsg || valiMsg;
					var exp = colModel._valiExp;
					if(exp == null) {
						var validate = this.trim(validate);
						if(validate.charAt(validate.length - 1) === "/") {
							validate += ".test(\"#{"+fieldName+"}\")";
						}
						exp = new qzz.expression();
						exp.setDataSet(this);
						var exps = {"exp":validate, "message":""};
			    		exp.setGJExpression(null, exps);
			    		colModel._valiExp = exp;
					}
					var tmpValue = node.data[fieldName];
					node.data[fieldName] = value;
		    		show = exp.getValue(node);
					node.data[fieldName] = tmpValue;
		    		if(typeof show != "boolean") {
		    			show = false;
		    		}
				}
			}
			return {"state":show,"message":valiMsg};
		},	    
		/**
	     * 获取过滤数据包.
	     * @return 返回过滤状态数据包.
	     */
	    getFilterMark:function() {
	    	var res = {};
	    	res.filterStack = this.extend([],this.filterStack);
	    	res.selectFilterList = this.extend({}, this.selectFilterList);
	    	res.topFilterItem = this.extend({}, this.topFilterItem);
	    	res.filterList = this.extend({},this.filterList);
	    	return res;
	    },
	    /**
	     * 设置过滤状态.
	     * @param filterStack 过滤数据包
	     * @param callBack 回调函数
	     */
	    setFilterMark:function(filterStack, callBack) {
	    	if(filterStack != null) {
	    		this.filterStack = filterStack.filterStack;
		    	this.selectFilterList = filterStack.selectFilterList;
		    	this.topFilterItem = filterStack.topFilterItem;
		    	this.filterList = filterStack.filterList;
		    	this.setFiltered(true, callBack);
	    	}
	    },
	    getCurData:function(node) {
	    	if(node == null) {
	    		 node =  this.dataSet.getCurNode();
	    	 }
	    	 return node.data;
	    },
		 /**
		  * 释放控件对象.
		  */
		 destroy:function() {
			 this.dateObject = null;
			 this.base();
		 }
	});
	return qzz.treedataset;
});
	